<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_type_id"]) 
{
	$agent_type_id = strip_tags($_REQUEST["agent_type_id"]);
	file_put_contents  ( "param_id.txt", $agent_type_id);
	
	$query = new Doctrine_Query();
    $query->from('Agent a')
    			->where('a.agent_type_id ='.$agent_type_id)
    			->orderby('name_full, name_short');
                  
    $items = $query->execute();  
} 
   
$dom = new DomDocument('1.0');
$dom->formatOutput = true;

$root = $dom->createElement( "results" );
$dom->appendChild( $root );

	foreach ($items as $item){
		$dn = $dom->createElement( "record" );		
		$dn->setAttribute( 'data', $item['agent_id'] );
		$dn->setAttribute( 'label', utf8_encode($item['name_full'].', '.$item['name_short']));
		$root->appendChild( $dn );
}		

header( "Content-type: text/xml");
echo $dom->saveXML();
    
?>